import json

jsonStr = """
{
  "status" : 40002,
  "data" : "验收单不存在",
  "flo":1.4,
  "arr":["1","2"],
  "arr2":[{"a":"1"},{"a":"2"}],
  "content":{
  "status" : 40002,
  "data" : "验收单不存在"
    }
}
"""

header = """
import Foundation
import HandyJSON

struct Bean:HandyJSON{
"""


class MakeHelper:
    def makeJson(self, json_str):
        obj = json.loads(json_str)
        self.makeDict(obj)

    @staticmethod
    def getType(value):
        if type(value) is int:
            return "Int"
        elif type(value) is float:
            return "Float"
        elif type(value) is str:
            return "String"
        return "unknown"

    @staticmethod
    def defaultValue(value):
        if type(value) is int:
            return "0"
        elif type(value) is float:
            return "0.0"
        elif type(value) is str:
            return " \"\" "
        pass

    def makeDict(self, dic):
        if type(dic) is not dict:
            return

        for key in dic:
            value = dic[key]
            if type(value) is dict:
                self.makeDict(value)
            elif type(value) is list:
                self.makeArr(value)
            else:
                print("var", key, ":", self.getType(value), "=", self.defaultValue(value))

    def makeArr(self, value: list):
        if len(value) > 0:
            for item in value:
                print("item:", item, " type:", type(item))


helper = MakeHelper()

print(header)
helper.makeJson(jsonStr)

print("}")
